<template>
	<view id="drawerbox">
		<view class="drawer-screen" v-show="isShow" @click="hideDrawer"></view>
		<view :animation="animationData" id="drawer" v-show="isShow"><slot></slot></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			isShow: false,
			animation: {},
			animationData: {},
			height: 1000
		};
	},
	props: {},
	onLoad() {},
	methods: {
		showDrawer() {
			this.animation = uni.createAnimation({
				duration: 800
			});
			this.animation.translateY(this.height).step();
			this.animationData = this.animation.export();
			this.isShow = true;
			setTimeout(()=>{
				this.animation.translateY(0).step();
				this.animationData = this.animation.export();
			},10)
		},
		hideDrawer() {
			this.animation.translateY(this.height).step();
			this.animationData = this.animation.export();
			setTimeout(() => {
				this.isShow = false;
			}, 800);
		},
		_cancel() {
			this.triggerEvent('cancel');
		},
		_confirm() {
			this.triggerEvent('confirm');
		}
	}
};
</script>

<style lang="scss" scoped>
#drawerbox {
	height: 100vh;
	.drawer-screen {
		width: 100%;
		height: 100%;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 800;
		background-color: rgba(0, 0, 0, 0.2);
		overflow: hidden;
	}

	#drawer {
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 888;
		background-color: #fff;
		height: 50vh;
		border-top-left-radius: 20upx;
		border-top-right-radius: 20upx;
	}
}
</style>
